
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<style>
    .btnBack{
        background: #ddd;
        margin-left: 20px;
        border: none;
        color: #fff;
        display: inline-block;
        padding: 6px 12px;
        font-size: 14px;
        border: 1px solid transparent;
        border-radius: 4px;
    }
</style>
<div class="modal" id="selectPOLineDiv" tabindex="-1" role="dialog" aria-hidden="true" style="width: auto;">

    <div class="modal-dialog modal-lg" role="document">

        <div class="modal-content animated bounceInRight">

            <div class="modal-header">
                <h4 class="modal-title">选择要入库/退货的单据行</h4>
                <button type="button" class="close" data-dismiss="modal"
                        aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>

            <div class="modal-body" style="padding-bottom: 20px; padding-top: 5px;">

                <div class="table-responsive">

                    <table class="table table-striped table-hover table-bordered border-top">
                        <thead>
                        <tr>
                            <th></th>
                            <th>物料编码</th>
                            <th>物料名称</th>
                            <th>规格</th>
                            <th>单价</th>
                            <th>发货数量</th>
                            <th>单位</th>
                            <th>金额</th>
                        </tr>
                        </thead>
                        <tbody>

                        <c:forEach items="${requestScope.noteLineList}" var="data" varStatus="status">
                            <tr>
                                <td><input type="checkbox" class="i-checks" name="input[]"></td>
                                <td class="id" style="display: none;">${data.id}</td>
                                <td class="materialCode">${data.materialCode}</td>
                                <td class="materialName">${data.materialName}</td>
                                <td class="standard">${data.standard}</td>
                                <td class="unitPrice">${data.unitPrice}</td>
                                <td class="purchasedAmount">${data.purchasedAmount}</td>
                                <td class="standardUnit">${data.standardUnit}</td>
                                <td class="sum">${data.sum}</td>
                            </tr>
                        </c:forEach>

                        </tbody>
                        <tfoot>
                        <%-- 导入页码 --%>
                        <jsp:include page="../../common/pages.jsp"></jsp:include>
                        </tfoot>
                    </table>
                </div>

                <div class="form-group row m-b-none">
                    <div class="col-sm-12  text-right">
                        <button class="btnBack" type="button" data-dismiss="modal">返回</button>
                        &nbsp;
                        <button id="selectButton" style="background:#2c74fa;" class="ladda-button ladda-button-demo btn btn-primary " data-style="expand-right">
                           继续
                        </button>
                    </div>
                </div>

            </div>

        </div>

    </div>

</div>

<script>
    $(document).ready(function() {

        //初始化checkbox
        $('.i-checks').iCheck({
            checkboxClass : 'icheckbox_square-green',
            radioClass : 'iradio_square-green',
        });


        //checkbox选中效果
        $("tr").click(function(){
            if($(this).find(".i-checks").prop("checked")){
                $(this).find(".i-checks").iCheck('uncheck');
            }else{
                $(".i-checks").iCheck('uncheck');
                $(this).find(".i-checks").iCheck('check');
            }

        });

        //确认按钮
        $("#selectButton").click(function(){
            var selectFlag = "N"
            var materialCode =  "";
            var materialName = "";
            var standard = "";
            var unitPrice = "";
            var purchasedAmount = "";
            var standardUnit = "";
            var sum = "";

            $('.i-checks').each(function(){
                if($(this).prop("checked")){
                    selectFlag = "Y";
                    lineId = $(this).parents("tr").find("td.id").text();
                    materialCode = $(this).parents("tr").find("td.materialCode").text();
                    materialName = $(this).parents("tr").find("td.materialName").text();
                    standard = $(this).parents("tr").find("td.standard").text();
                    unitPrice = $(this).parents("tr").find("td.unitPrice").text();
                    purchasedAmount = $(this).parents("tr").find("td.purchasedAmount").text();
                    standardUnit = $(this).parents("tr").find("td.standardUnit").text();
                    sum = $(this).parents("tr").find("td.sum").text();
                    return false;
                }
            });

            if(selectFlag=="N"){
                redragonJS.alert("必须选择一个单据行");
            }else{
                $('#selectPOLineDiv').modal('hide');
                debugger
                getLineModal(null, lineId, materialCode, materialName, unitPrice, purchasedAmount, standardUnit, sum, standard);
            }
        });
    });
</script>
